package collectionTest;

import java.util.TreeSet;

/**
 * @author shentianyu
 * @date 2021-06-13 21:47
 *
 * TreeSet
 * 红黑树
 * 元素要实现Comparable接口
 */
public class TreeSetTest {
    public static void main(String[] args) {
        TreeSet<String> treeSet = new TreeSet<>();
        treeSet.add("hello");
        treeSet.add("hi");
        treeSet.add("apple");
        treeSet.add("orange");
        treeSet.add("xiaomi");
        treeSet.add("huawei");

        for (String s:treeSet
             ) {
            System.out.println(s);
        }

        TreeSet<Student> students = new TreeSet<>();
        students.add(new Student("hello",20));
        students.add(new Student("abc",22));
        students.add(new Student("xyz",21));
        System.out.println(students.toString());
    }
}
